﻿using System;
using System.Web.Mvc;

namespace ValidationFramework.Web.MVC
{
	public static class ClientValidation
	{
		public static string GenerateScripts(string htmlFormId, ViewContext viewContext)
		{
			var generator = new JQueryGenerator(new PropertyToElementConverter());
			var strategy = new TypeExtractionStrategy(viewContext.ViewData.Model.GetType());
			var engine = new ClientValidationEngine(new RuleExtractor(strategy), generator);
			return engine.GenerateScript(htmlFormId);
		}
		public static string GenerateScripts(string htmlFormId, Type modelType)
		{
			var generator = new JQueryGenerator(new PropertyToElementConverter());
			var strategy = new TypeExtractionStrategy(modelType);
			var engine = new ClientValidationEngine(new RuleExtractor(strategy), generator);
			return engine.GenerateScript(htmlFormId);
		}
		public static string GenerateScripts(string htmlFormId, Type modelType, string whitelist)
		{
			var generator = new JQueryGenerator(new PropertyToElementConverter());
			var strategy = new TypeExtractionStrategy(modelType, whitelist);
			var engine = new ClientValidationEngine(new RuleExtractor(strategy), generator);
			return engine.GenerateScript(htmlFormId);
		}
		public static string GenerateScripts(string htmlFormId, Type modelType, string list, bool isWhiteList)
		{
			var generator = new JQueryGenerator(new PropertyToElementConverter());
			var strategy = new TypeExtractionStrategy(modelType, list, isWhiteList);
			var engine = new ClientValidationEngine(new RuleExtractor(strategy), generator);
			return engine.GenerateScript(htmlFormId);
		}
		public static string GenerateScripts(string htmlFormId, IRuleExtractionStrategy strategy)
		{
			var generator = new JQueryGenerator(new PropertyToElementConverter());
			var engine = new ClientValidationEngine(new RuleExtractor(strategy), generator);
			return engine.GenerateScript(htmlFormId);
		}
		public static string GenerateScripts(string htmlFormId, IRuleExtractionStrategy strategy, IClientValidationGenerator generator)
		{
			var engine = new ClientValidationEngine(new RuleExtractor(strategy), generator);
			return engine.GenerateScript(htmlFormId);
		}
	}
}
